#include "vsLogger.h"

using namespace vs;
using namespace vs::log;

/*
1 create a output
FileOutput *file_output = new FileOutput("first");
FileOutput *file_output_second = new FileOutput("second", "file_out_put");

2 create a logger
Logger *logger = LogManager::GetLogger("test");

3 add the output to logger
logger->AddLogOutput();
logger->AddLogOutput();

4 log messages
logger->LogMsg(LOG_INFO, "this is a test message id = %d\r\n", 1);
*/

void test_simple_logger()
{
	Logger default_logger;
	
	LogOutput *file_output = new FileOutput();
	LogOutput *file_output_second = new FileOutput("file_out_put");
	LogOutput *file_output_third = new StdOutput();
	default_logger.AddLogOutput(file_output);
	default_logger.AddLogOutput(file_output_second);

	default_logger.LogMsg(LOG_WARN, "this is a test message id = %d\r\n", 1);
	default_logger.LogMsg(LOG_DEBUG, "this is a test message id = %d, but you can't see it on the screen\r\n", 2);

	default_logger.SetLogFormat("%T %R");
	default_logger.LogMsg(LOG_INFO, "this is a test message id = %d\r\n", 3);
	default_logger.SetLogFormat("%Y%M%D%h%m%s %R");
	default_logger.LogMsg(LOG_WARN, "this is a test message id = %d\r\n", 4);
	default_logger.SetLogFormat("%L %R");
	default_logger.LogMsg(LOG_ERROR, "this is a test message id = %d\r\n", 5);
	default_logger.SetLogFormat("%l %R");
	default_logger.LogMsg(LOG_FATAL, "this is a test message id = %d\r\n", 6);

	default_logger.SetLogLevel(LOG_DEBUG);
	default_logger.SetLogFormat("%p %t %R");
	default_logger.LogMsg(LOG_DEBUG, "this is a test message id = %d\r\n", 7);


	default_logger.RemoveLogOutput(file_output);
	
	default_logger.LogMsg(LOG_FATAL, "this is a test message id = %d\r\n", 8);

	default_logger.RemoveAllLogOutput();
	default_logger.LogMsg(LOG_FATAL, "this is a test message id = %d\r\n", 9);

	default_logger.AddLogOutput(file_output_third);
	default_logger.LogMsg(LOG_FATAL, "this is a test message id = %d\r\n", 10);

	delete file_output;
	delete file_output_second;

	// do not delete this, the logger will delete it
	//delete file_output_third;
}

void test_fixed_logger()
{
	Logger default_logger;

	LogOutput *file_output = new FixedSizeFileOutput(102400, "fixed");

	default_logger.AddLogOutput(file_output);


	for (int i=0; i<100000; ++i)
	{
		default_logger.LogMsg(LOG_WARN, "this is a test message id = %d\r\n", i);
	}
	
}

void test_timed_logger()
{
	Logger default_logger;

	LogOutput *file_output = new TimeRollingOutput(TimeRollingOutput::ROLLING_BY_SECOND, "timed");

	default_logger.AddLogOutput(file_output);


	for (int i=0; i<100; ++i)
	{
		default_logger.LogMsg(LOG_WARN, "this is a test message id = %d\r\n", i);
		Sleep(10);
	}

}



int main(int argc, char **argv)
{
	test_simple_logger();
	test_fixed_logger();
	test_timed_logger();

	return 0;
}
